<html>
<head>
<link rel='stylesheet' href='../../js/sh/SyntaxHighlighter.css' type='text/css' />
<script src='../../js/sh/shCore.js'></script>
<script src='../../js/sh/shBrushJava.js'></script>
<style>
* {
font-family:Courier New,monospace;
  padding: 0;
  margin: 0;
  white-space: nowrap;
  font-size: 11px;
}
.dp-highlighter {
  white-space: nowrap;
  overflow: visible;
  width: 600px;
  font-size: 11px;
  font-family:Courier New,monospace;
}
</style>
</head>
<body>
<textarea name='code' class='java:nogutter' rows='15' cols='120'>
/*
 * SmartGWT (GWT for SmartClient)
 * Copyright 2008 and beyond, Isomorphic Software, Inc.
 *
 * SmartGWT is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation.  SmartGWT is also
 * available under typical commercial license terms - see
 * http://smartclient.com/license
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 */

import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.menu.*;

public class MenuDynamicItemsSample implements EntryPoint {
    

    class ProjectRecord extends ListGridRecord {
        ProjectRecord(String project) {
            setAttribute("project", project);
        }
    }

    //TODO this sample is incomplete
    public void onModuleLoad() {

        final ListGrid listGrid = new ListGrid();
        listGrid.setWidth(130);
        listGrid.setFields(new ListGridField("project", "Project"));
        listGrid.setData(new ProjectRecord[]{
                new ProjectRecord("AJAX Interface"),
                new ProjectRecord("Simplify Backend"), new ProjectRecord("Broaden Reach")});


        Menu menu = new Menu();
        menu.setShowShadow(true);
        menu.setShadowDepth(10);

        final MenuItem newItem = new MenuItem("New file in...", "icons/16/document_plain_new_Disabled.png", "Ctrl+N");
        newItem.setEnableIfCondition(new MenuItemIfFunction() {
            public boolean execute(Canvas target, Menu menu, MenuItem item) {
                return listGrid.getSelectedRecord() != null;
            }
        });
        MenuItem openItem = new MenuItem("Open", "icons/16/folder_out.png", "Ctrl+O");
        MenuItem saveItem = new MenuItem("Save", "icons/16/disk_blue.png", "Ctrl+S");
        MenuItem saveAsItem = new MenuItem("Save As", "icons/16/save_as.png");

        MenuItem projectItem = new MenuItem("Project Listing");
        projectItem.setChecked(true);

        MenuItemSeparator separator = new MenuItemSeparator();

        //menu.setData(newItem, openItem, separator, saveItem, saveAsItem, separator, projectItem);
        menu.addItem(newItem);
        menu.addItem(openItem);
        menu.addItem(separator);
        menu.addItem(saveItem);
        menu.addItem(saveAsItem);
        menu.addItem(separator);
        menu.addItem(projectItem);
                
        MenuButton menuButton = new MenuButton("File", menu);

        VLayout hLayout = new VLayout();
        hLayout.addMember(listGrid);
        hLayout.addMember(menuButton);

        hLayout.draw();
    }

}
</textarea>
<script class='javascript'>
dp.SyntaxHighlighter.HighlightAll("code");
</script>
</body>
</html>
